<?php
/**
* Class Select
* Class for creating HTML select fields
* 
*/
class SelectField{
	/**
	* @var string $output
	* @access private
	* Content of class
	*/
	var $output;
	
	/**
	* Constructor function
	* @param string $name
	* @param string $onChange
	*/
	function SelectField($name, $onChange="", $multiple=false, $size="", $class=""){
		$onChangeAction="";
		if ($onChange!="") $onChangeAction="onChange=\"$onChange\"";
		if ($multiple) $mulipleText="multiple=\"multiple\" size=\"$size\"";
		if ($class!="") $clasText="class=\"$class\"";
		$this->output="\n<select name=\"$name\" $onChangeAction $mulipleText $clasText>\n";

	}
	
	/**
	* Adds one option to select field
	* @param string $name
	* @param string $value
	* @return boolean $selected True if option should be selected, otherwise false
	*/
	function append_option($text, $value, $selected=false, $class=""){
		$is_selected="";
		if ($selected==true) $is_selected=" selected";
		if ($class!="") $classText=" class=\"$class\"";
		$this->output.="\t<option$classText value=\"$value\"$is_selected>$text</option>\n";
	}
	
	/**
	* Returns HTML output
	* @return string The select field in HTML syntax
	*/
	function print_html(){
		$this->output.="</select>\n";
		return $this->output;
	}	
}
?>
